package cn.acewill.yxd.yunxundian.ui.user.Presenter;

import android.text.TextUtils;

import java.io.IOException;
import java.util.HashMap;

import cn.acewill.yxd.yunxundian.pubClass.OkHttpManger;
import cn.acewill.yxd.yunxundian.pubClass.pubClass;
import cn.acewill.yxd.yunxundian.ui.user.Contract.IpconfigListener;
import cn.acewill.yxd.yunxundian.ui.user.Contract.LoginLModel;
import cn.acewill.yxd.yunxundian.ui.user.Contract.LoginListener;

/**
 * Created by xxx on 2018/1/9.
 * Login 实现类
 */

public class LoginModelIml implements LoginLModel {
    @Override
    public void onUserLogin(String name, String pass,String ipName, final LoginListener loginListener) {
        HashMap<String, String> map = new HashMap<>();
        map.put("task","loginByUserNumAndPwd");
        map.put("usernum",name);
        map.put("pwd",pass);
        try {
            OkHttpManger.getInstance().postAsync(pubClass.Server_namehzm, new OkHttpManger.MyCallback() {
                @Override
                public void onSuccess(String result) {
                    loginListener.onLoginSuccess(result);
                }

                @Override
                public void onFailture() {
                    loginListener.onLoginFailed();
                }
            }, map);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void checkIpAvild(String code, String pwd, final IpconfigListener ipconfigListener) {
        HashMap<String, String> map = new HashMap<>();
        map.put("task","getServerInfo");
        map.put("code",code);
        map.put("pwd",pwd);
        try {
            OkHttpManger.getInstance().postAsync(pubClass.checkUrl, new OkHttpManger.MyCallback() {
                @Override
                public void onSuccess(String result) {
                    ipconfigListener.onRequestSuccess(result);
                }

                @Override
                public void onFailture() {
                    ipconfigListener.onRequestErro();
                }
            },map);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
